<script type="text/javascript">
	$(document).ready(function() {
			$('#routestable').tableDnD({onDrop: routeDrop});
			$("#routestable tr:even").addClass("routeeven");
			$("#routestable tr:odd").addClass("routeodd");
	});

function routeDrop(table,row) {
	$("#routestable tr:even").addClass("routeeven");
	$("#routestable tr:even").removeClass("routeodd");
	$("#routestable tr:odd").addClass("routeodd");
	$("#routestable tr:odd").removeClass("routeeven");

	//reset all hidden's
	var rows = table.tBodies[0].rows;
	for (var i=0; i<rows.length; i++) {
		$('#route' + rows[i].id).val(i);
	}
}
</script>

<table id="routestable">
<thead>
<tr class="nodrop nodrag"><th>Name</th><th>Description</th></tr>
</thead>
<tbody>
<% routes.each do |r| %>
	<tr id="<%= r.id %>">
		<td><%= h(r.name) %></td>
		<td><%= h(r.description) %></td>
	</tr>
<% end %>
</tbody>
</table>

<% form_tag formsubmit do -%>
<% routes.each_with_index do |r,index| %>
	<%= hidden_field_tag('route'+r.id.to_s,index) %>
<% end %>
<%= submit_tag 'Save Order' %>
<% end %>
